package com.zlzxm.shoesmarket.view.widget;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;

/**
 * CREATE BY zlzxm ON 4/16/21
 */
public class GoodsInfoView extends RelativeLayout {


    private TextView tvName,tvCode,tvBrand;
    private ImageView ivFace;

    public GoodsInfoView(Context context) {
        this(context,null);
    }

    public GoodsInfoView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public GoodsInfoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }


    private void init(Context context){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            setTransitionName(context.getString(R.string.transition_goods_info));
        }

        LayoutInflater.from(context).inflate(R.layout.layout_goods_info,this,true);

        tvName  = ZViewHelp.findById(this,R.id.tvName);
        tvCode  = ZViewHelp.findById(this,R.id.tvCode);
        tvBrand  = ZViewHelp.findById(this,R.id.tvBrand);
        ivFace  = ZViewHelp.findById(this,R.id.ivFace);


    }


    public void updateName(String name){

        tvName.setText(name);

    }

    public void updateCode(String code){

        tvCode.setText("货号："+code);

    }

    public void updateBrand(String brand){

        tvBrand.setText("品牌:"+brand);


    }

    public void updateFace(String url){


        RequestOptions requestOptions = new RequestOptions().transform(new CenterCrop()
                ,new RoundedCorners(ZViewHelp.dpTopx(getContext(),4)));

        Glide.with(this)
                .load(url)
                .apply(requestOptions)
                .into(ivFace);

    }

}
